package com.boesch.electroOffice.dataaccess.mapper;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.boesch.electroOffice.model.electroOffice.MeasurementEntry;
import com.boesch.electroOffice.utils.DateUtils;

/**
 * This class mappes the rows from database to a MeasurementEntry object.
 * 
 * @author Ralph Koster
 *
 */
public class MeasurementEntryMapper implements RowMapper<MeasurementEntry>, Serializable {

	private static final long serialVersionUID = -8659168699847030625L;

	/**
	 * Mapps all rows from database to a MeasurementEntry object.
	 * 
	 * @see org.springframework.jdbc.core.RowMapper
	 */
	public MeasurementEntry mapRow(ResultSet rs, int rowNum) throws SQLException {
		MeasurementEntry measurementEntry = new MeasurementEntry();
		measurementEntry.setId(rs.getInt("Id_pk"));
		measurementEntry.setCurrentCircuitNumber(rs.getString("Currentcircuitnumber"));
		measurementEntry.setDescription(rs.getString("Description"));
		measurementEntry.setConductorCrossSection(rs.getString("Conductorcrosssection"));
		measurementEntry.setCharacteristic(rs.getString("Characteristic"));
		measurementEntry.setRatedCurrent(rs.getString("Ratedcurrent"));
		measurementEntry.setPeConductibility(rs.getString("Peconductibility"));
		measurementEntry.setShortCircuitCurrent(rs.getString("Shortcircuitcurrent"));
		measurementEntry.setInsulatingResistance(rs.getString("Insulatingresistance"));
		measurementEntry.setInsulatingResistanceIsBigger999(rs.getBoolean("Insulatingresistanceisbigger999"));
		measurementEntry.setFiRatedCurrent(rs.getString("Firatedcurrent"));
		measurementEntry.setFiReleaseCurrent(rs.getString("Fireleasecurrent"));
		measurementEntry.setFiTimeInMillis(rs.getString("Fitimeinmillis"));
		measurementEntry.setRotatingFieldClockwise(rs.getBoolean("Rotatingfieldclockwise"));
		measurementEntry.setCreatedBy(rs.getString("Createdby"));
		measurementEntry.setCreatedAt(DateUtils.convertTimestampToLocalDateTime(rs.getTimestamp("Createdat")));
		measurementEntry.setModifiedBy(rs.getString("Modifiedby"));
		measurementEntry.setModifiedAt(DateUtils.convertTimestampToLocalDateTime(rs.getTimestamp("Modifiedat")));
		measurementEntry.setVersion(rs.getInt("Version"));

		return measurementEntry;
	}
}
